﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinForms窗体练习.Model;

namespace WinForms窗体练习
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void tabPage1_Click(object sender, EventArgs e)
        {

        }
        private void btnA_Click(object sender, EventArgs e)
        {
            string name = txtName.Text.Trim();
            var sex = "";
            if (rdomen.Checked)
            {
                sex = "男";
            }
            if (rdonv.Checked)
            {
                sex = "女";
            }
            var address = cboAdder.Text;
            List<string> hobby = new List<string>();
            foreach (var item in chkHobby.CheckedItems)
            {
                hobby.Add(item.ToString());
            }
            string hobbys = string.Join(";", hobby);

            MessageBox.Show($"姓名：{name}\n性别：{sex}\n爱好：{hobbys}\n地址；{address}");
        }

        private void tabPage2_Click(object sender, EventArgs e)
        {

        }


        private void Form2_Load(object sender, EventArgs e)
        {
            List<UserModel> users = new List<UserModel>()
            {
                new UserModel(){ Id=1,UserName="admin",RealName="张三",Email="1234567890@qq.com"},
                new UserModel(){ Id=2,UserName="lisi",RealName="李四",Email="0987654321@qq.com"},
                new UserModel(){ Id=3,UserName="wangwu",RealName="王五",Email="9638527410@qq.com"},
                new UserModel(){ Id=4,UserName="zhaoliu",RealName="赵六",Email="1478523690@qq.com"},
                new UserModel(){ Id=5,UserName="enen",RealName="嗯嗯",Email="5896320147@qq.com"},
            };
            this.dgvUser.DataSource = users;

            //// 修改列标题
            //this.dgvUser.Columns["Id"].HeaderText = "编号";
            //this.dgvUser.Columns["UserName"].HeaderText = "用户名";
            //this.dgvUser.Columns["RealName"].HeaderText = "真实姓名";
            //this.dgvUser.Columns["Email"].HeaderText = "电子邮箱";
            //this.dgvUser.Columns["Password"].HeaderText = "密码";

            List<AdderModel> adders = new List<AdderModel>()
            {
                new AdderModel { Id = 1, AddrName = "河北" },
                new AdderModel { Id = 2, AddrName = "北京" },
                new AdderModel { Id = 3, AddrName = "黑龙江" }
            };
            cboAdder.DataSource = adders;//数据源
            cboAdder.DisplayMember = "AddrName";//指定显示的字段
            cboAdder.ValueMember = "Id";//绑定id属性
            cboAdder.SelectedIndex = 1;//默认选中

            //dgvUser.CellBeginEdit += dgvUser_CellEndEdit;
        }

        private void 生成解决方案ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form1 form1 = new Form1(9999, "张三");//构造函数传参
            form1.Show();
        }
    }
}
